extends Block

var DEFAULT_COLOR = Color8(108,0,136,255)

func _init():

	RISE_TIME = 0.2
	OVERALL_TIME = 0.5
	FALL_TIME = OVERALL_TIME - RISE_TIME

	EXPANDED_MARGIN = 0.1
	HIGHLIGHTED_COLOR = DEFAULT_COLOR.lightened(0.5)


	shader = load('res://shaders/projection_shader.shader')
	color = DEFAULT_COLOR
	margin = 0.2

func check_completed():
	pulsate()

	var block = Grid.get_block(_i,_j)

	if block:
		block.block_pulsate()
		return true
	else:
		return false

func pulsate():
	var ani_progress = 0

	var colortw1 = SDTween.new()
	colortw1.interpolate_property($TextureRect,"material:shader_param/color",$TextureRect.material.get_shader_param("color"),HIGHLIGHTED_COLOR,RISE_TIME,Tween.TRANS_CUBIC,Tween.EASE_OUT)
	add_child(colortw1)
	colortw1.start()

	var margintw1 = SDTween.new()
	margintw1.interpolate_property($TextureRect,"material:shader_param/margin",$TextureRect.material.get_shader_param("margin"),EXPANDED_MARGIN,RISE_TIME,Tween.TRANS_CUBIC,Tween.EASE_OUT)
	add_child(margintw1)
	margintw1.start()

	ani_progress+=RISE_TIME

	var colortw2 = SDTween.new()
	colortw2.interpolate_property($TextureRect,"material:shader_param/color",HIGHLIGHTED_COLOR,color,FALL_TIME,Tween.TRANS_CUBIC,Tween.EASE_OUT,ani_progress)
	add_child(colortw2)
	colortw2.start()

	var margintw2 = SDTween.new()
	margintw2.interpolate_property($TextureRect,"material:shader_param/margin",EXPANDED_MARGIN,margin,FALL_TIME,Tween.TRANS_CUBIC,Tween.EASE_OUT,ani_progress)
	add_child(margintw2)
	margintw2.start()


